<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('扣款单')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
	<!-- <style type="text/css">.table {table-layout:fixed;}</style> -->
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="cutpayHeaderForm" th:action="@{/cutpayHeader/list}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3" style="width: 33%">
                               <label>扣款单号：</label>
                               <input type="text" name="coNO" />
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                              <label>扣款单类型：</label>
                              <input type="text" name="coType" />
                        </li>
                        <li class="col-sm-3" style="width: 33%">
	                            <label>供应商编号：</label>
	                            <input type="text" name="vendorCode"/>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <div>
	                            <label>工厂：</label>
	                            <select id="factory" name="factory" sysDict="GC" emptyFirst="true"></select>
                            </div>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <label >采购组：</label>
                            <select name="purchGroup" sysDict="CGZ" emptyFirst="true"></select>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <button id="cutpayHeaderSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="cutpayHeaderAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        
        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="cutpayHeaderToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="toAddcutpayHeader()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEditcutpayHeader()">
                    <i class="fa fa-edit"></i> 编辑
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="deleteCutpayHeader()">
                    <i class="fa fa-edit"></i> 删除
                </a>
            </div>
            <div style="height:360px; overflow:auto;">
            	<table id="cutpayHeader" data-mobile-responsive="true"></table>
            </div>
            <div>
            	<table id="cutpayItem" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<!-- Page-Level Scripts -->

<!--  -->
<script type="text/javascript">
	var itemBS = Searcher.createBS('#cutpayItem',
	        [
	            {title: '扣款单号', field:'coNo'},
	            {title: '采购订单号', field:'poNo'},
	            {title: '采购订单行项目号', field:'poItemNo'},
	            {title: '物料编码', field:'materialCode'},
	            {title: '物料描述', field:'materialDesc'},
	            {title: '扣款发票号', field:'invoiceNo'},
	            {title: '扣款金额', field:'cutMoney'},
	            {title: '发票金额', field:'invoiceMoney'},
	            {title: '应付金额', field:'payMoney'},
	            {title: '货币单位', field:'currencyUnit'},
	            {title: '发票日期', field:'invoiceDate',
                    formatter:function(value,row,index){
                        if(value!=null&&value!=undefined&&value!=''){
                            var date=new Date(value);
                            return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
                        }
                    }
                },
	            {title: '抱怨日期', field:'complainDate',
                    formatter:function(value,row,index){
                        if(value!=null&&value!=undefined&&value!=''){
                            var date=new Date(value);
                            return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
                        }
                    }
                },
	            {title: '备注', field:'remark'}
	        ], {"showColumns": false,"showRefresh": false, "firstLoad": false}
	);
  
    //面向对象
    var searcherBS= Searcher.createBS('#cutpayHeader',
        [
            {radio: true},
            {title: '扣款单号', field:'coNo'},
            {title: '扣款单类型', field:'coType'},
            {title: '工厂', field:'factory'},
            {title: '采购订单号', field:'poNo'},
            {title: '采购组', field:'purchGroup'},
            {title: '供应商代码', field:'vendorCode'},
            {title: '供应商名称', field:'vendorName'},
            {title: '删除标志', field:'deleteFlag'},
            {title: '创建人', field:'createdBy'},
            {title: '创建日期', field:'creationDate',
                formatter:function(value,row,index){
                    if(value!=null&&value!=undefined&&value!=''){
                        var date=new Date(value);
                        return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
                    }
                }
            },
            {title: '修改人', field:'lastUpdatedBy'},
            {title: '修改日期', field:'lastUpdateDate'}
        ], {pageList: [5, 10, 15, 50, 100], pageSize : 5,
    	onCheck : function(row) {itemBS.getData({'url': ctxPath + '/cutpayItem/list?coNo='+row.coNo});},
    	onPostBody : function() {$("#cutpayItem").bootstrapTable('removeAll');}
    	}
    );
    
    //刷新数据
    function refresh() {
    	searcherBS.refresh();
    }
    
    initDictDataSel();//初始化所有字典数据
    
    /**
     * 跳转至新增页
     */
    function toAddcutpayHeader() {
        var index=Dialog.openUrl("新增扣款单", ctxPath + '/modules/paycut/paycut_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {}
        });
        layer.full(index);
    }
 
    /**
     * 编辑
     */
    function toEditcutpayHeader() {
    	//field:"pkId"
        var rowDatas = searcherBS.getSelectedRows("pkId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
		var index = Dialog.openUrl("编辑扣款单", ctxPath + '/cutpayHeader/toEdit/'+rowDatas,
		    {area : ['900px','700px'],
			  maxmin: true,
		      end: function () {}
		    });
		layer.full(index)
    }

    function deleteCutpayHeader() {
        var rowDatas = searcherBS.getSelectedRows("pkId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/cutpayHeader/delete", {userIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        });
    }
</script>
</body>
</html>